<?php
class Project{
	function Project(){
		include("project.methodTable.php");
		include("database.php");
	}
	function getProject($projectId){
		if (isset($projectId)) $WHERE = " WHERE project.projectId={$projectId}";
		$sql = "SELECT * FROM project $WHERE";
		$query = mysql_query($sql);
		$result = mysql_fetch_object($query);
		return $result;
	}
	function getStudentProjects($userId){
		if (isset($userId)) $WHERE = " WHERE project_user.userId={$userId}";
		$sql = "SELECT * FROM project INNER JOIN project_user ON project.projectId = project_user.projectId $WHERE";
		$query = mysql_query($sql);
		$result = array();
		while($object = mysql_fetch_object($query)){
			array_push($result, $object);
		}
		return $result;
	}
	function getRating($projectId){
		if (isset($projectId)) $WHERE = " WHERE projectId={$projectId}";
		$sql = "SELECT AVG(rating) AS rating FROM rating $WHERE";
		$query = mysql_query($sql);
		$result = mysql_fetch_object($query);
		return $result;
	}
}
?>